package hlhj.fhp.supreme.activitys

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.support.v7.app.AlertDialog
import android.support.v7.widget.LinearLayoutManager
import android.widget.LinearLayout
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.adapters.ViewPagerAdp
import hlhj.fhp.supreme.fragment.OrderFgm
import hlhj.fhp.supreme.javabean.BaseBean
import hlhj.fhp.supreme.javabean.OrderListBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import hlhj.fhp.supreme.utils.MyUtils
import kotlinx.android.synthetic.main.activity_order_aty.*
import java.util.ArrayList

class OrderAty : BaseAty(), ViewPager.OnPageChangeListener, TabLayout.OnTabSelectedListener {

    override fun getContentId(): Int = R.layout.activity_order_aty
    private lateinit var allFgm:Fragment
    private lateinit var unPayFgm:Fragment
    private lateinit var ungetFgm:Fragment
    private lateinit var finishFgm:Fragment
    private var fragments=ArrayList<Fragment>()
    private lateinit var pagerAdp:ViewPagerAdp
    override fun initView() {
        initFgm()
    }

    private fun initFgm() {
        allFgm=OrderFgm.getInstence("1")
        unPayFgm=OrderFgm.getInstence("2")
        ungetFgm=OrderFgm.getInstence("3")
        finishFgm=OrderFgm.getInstence("4")

        fragments.add(allFgm)
        fragments.add(unPayFgm)
        fragments.add(ungetFgm)
        fragments.add(finishFgm)

        pagerAdp=ViewPagerAdp(supportFragmentManager,fragments)
        viewPager.adapter=pagerAdp

    }


    override fun initListener() {
        viewPager.addOnPageChangeListener(this)
        tabLayout.addOnTabSelectedListener(this)
        btExit.setOnClickListener {
            finish()
        }

    }


    override fun onPageScrollStateChanged(state: Int) {
    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
    }

    override fun onPageSelected(position: Int) {
//        tabLayout.getTabAt(position)?.select()

    }

    override fun onTabReselected(tab: TabLayout.Tab?) {
    }

    override fun onTabUnselected(tab: TabLayout.Tab?) {
    }

    override fun onTabSelected(tab: TabLayout.Tab?) {
        val position = tab?.position
        if (position != null) {
            viewPager.currentItem = position
        }
    }
}
